import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const routes = [
  {
    path: '*',
    redirect: '/allActivity'
  },
  // {
  //   name: 'index',
  //   component: () => import('./view/main'),
  //   meta: {
  //     title: '首页'
  //   }
  // },
  {
    name: 'addInfo',
    component: () => import('./view/addInfo'),
    meta: {
      title: '资料填写'
    }
  },
  {
    name: 'allActivity',
    component: () => import('./view/activity/allActivity'),
    meta: {
      title: '所有活动'
    }
  },
  {
    name: 'myActivity',
    component: () => import('./view/activity/myActivity'),
    meta: {
      title: '我的活动列表'
    }
  },
  {
    name: 'activityInfo',
    component: () => import('./view/activity/activityInfo'),
    meta: {
      title: '活动信息'
    }
  },
  {
    name: 'activityDetail',
    component: () => import('./view/activity/activityDetail'),
    meta: {
      title: '活动详情'
    }
  },
  // {
  //   name: 'searchInfo',
  //   component: () => import('./view/searchInfo'),
  //   meta: {
  //     title: '活动查询'
  //   }
  // },
  {
    name: 'searchResult',
    component: () => import('./view/searchResult'),
    meta: {
      title: '查询结果'
    }
  },
  {
    name: 'paymentInfo',
    component: () => import('./view/paymentInfo'),
    meta: {
      title: '缴费信息'
    }
  },
  {
    name: 'aboutUs',
    component: () => import('./view/aboutUs'),
    meta: {
      title: '关于我们'
    }
  },
  {
    name: 'contactUs',
    component: () => import('./view/contactUs'),
    meta: {
      title: '联系我们'
    }
  },
  {
    name: 'nodata',
    component: () => import('./components/noData'),
    meta: {
      title: '暂无数据'
    }
  },
  {
    name: 'auth',
    component: () => import('./view/auth'),
    meta: {
      title: '微信授权认证'
    }
  }
]

// add route path
routes.forEach((route) => {
  route.path = route.path || '/' + (route.name || '')
})

const router = new Router({ routes, mode: 'history', base: '/nanc-h5/' })

router.beforeEach((to, from, next) => {
  const title = to.meta && to.meta.title
  if (title) {
    document.title = title
  }
  next()
})

export { router }
